package jp.co.toshiba.ffsa.action.csde;

import java.util.ArrayList;

import javax.annotation.Resource;

import jp.co.toshiba.ffsa.action.common.CommonAction;
import jp.co.toshiba.ffsa.form.csde.Csde202Form;
import jp.co.toshiba.ffsa.service.common.ConstantValue;

import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.util.MessageResourcesUtil;

/**
 * 設計I/F - 新規プロジェクト作成
 * @author npc
 */
public class Csde202Action extends CommonAction {

    /** 画面ID */
    public String screenID = "CSDE202";

    /** アクションフォーム */
    @ActionForm
    @Resource
    protected Csde202Form csde202Form;

    /**
     * 初期処理
     * @return 画面遷移先
     * @throws Exception
     */
    @Execute(validator = false)
    public String index() throws Exception {
        // ログイン済判定する
        if(this.judgeLogin(csde202Form.getSessionId())){
            try {
                // リファラ判定
                if(this.judgeRefferer()){
                    // 初期セット
                    if(this.csde202Form.returnFlag == null || this.csde202Form.returnFlag.equals("")){
                        this.csde202Form.projectName = "";
                        this.csde202Form.description = "";
                    }
                    return "/csde/csde202.jsp";
                }else{
                    return this.topTransition;
                }
            } catch (Exception e) {
                this.errorLogWriter(e, "index", this.screenID);
                throw e;
            }
        }else{
            return this.topTransition;
        }
    }

    /**
     * プロジェクト作成
     * @return 画面遷移先
     * @throws Exception
     */
    @Execute(validator = true,input="/csde/csde202/error")
    public String create() throws Exception {
        String transition = "/csde/csde202";
        String result = "";
        // ログイン済判定する
        if(this.judgeLogin(csde202Form.getSessionId())){
            try {
                // リファラ判定
                if(this.judgeRefferer()){
                    transition = "/csde/csde203.jsp";
                    result = ConstantValue.success;
                    // 操作ログ記述
                    ArrayList<ArrayList<String>> parameters = new ArrayList<ArrayList<String>>();
                    ArrayList<String> parameterNames = new ArrayList<String>();
                    ArrayList<String> values = new ArrayList<String>();
                    parameterNames.add(MessageResourcesUtil.getMessage("csde202.003"));
                    values.add(this.csde202Form.projectName);
                    parameterNames.add(MessageResourcesUtil.getMessage("csde202.004"));
                    values.add(this.csde202Form.description);
                    parameters.add(parameterNames);
                    parameters.add(values);
                    this.entryOperationHistory(this.screenID, "submit", parameters, result);

                    return transition;
                }else{
                    return this.topTransition;
                }

            } catch (Exception e) {
                this.errorLogWriter(e, "create", this.screenID);
                throw e;
            }
        }else{
            return this.topTransition;
        }
    }
    /**
     * バリデーションエラー処理
     * @return 遷移先
     * @throws Exception
     */
    @Execute(validator=false)
    public String error() throws Exception {
        // ログイン済判定する
        if(this.judgeLogin(csde202Form.getSessionId())){
            try {
                // リファラ判定
                if(this.judgeRefferer()){
                    // セッションタイムアウト判定
                    if(this.judgeSession()){
                        return index();
                    }else{
                        return this.topTransition;
                    }
                }else{
                    return this.topTransition;
                }
            }catch(Exception e) {
                this.errorLogWriter(e, "create", this.screenID);
                throw e;
            }
        }else{
            return this.topTransition;
        }
    }

}